//
//  RestaurantReviewSectionController.swift
//  FeastBooking
//
//  Created by Imon on 2017/11/19.
//  Copyright © 2017年 Imon. All rights reserved.
//
import UIKit
import IGListKit

class RestaurantReviewSectionController: ListSectionController {
    
    var restaurantReview: RestaurantReview!
    
    override init() {
        super.init()
        inset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    }
    
    override func numberOfItems() -> Int {
        return 1
    }
    
    override func sizeForItem(at index: Int) -> CGSize {
        guard let context = collectionContext else {return .zero}
        let width = context.containerSize.width
        var height: CGFloat = 0;
        if let review = restaurantReview.review {
            let maxSize = CGSize(width: width - 55, height: context.containerSize.height)
            let reviewSize = TextSize.textSize(text: review, font: AppFont(size: 12), maxSize: maxSize)
            height = reviewSize.height
        }
        return CGSize(width: width, height: height + 80)
    }
    
    override func cellForItem(at index: Int) -> UICollectionViewCell {
        let cell = collectionContext!.dequeueReusableCell(of: RestaurantReviewCollectionViewCell.self, for: self, at: index)
        if let cell = cell as? RestaurantReviewCollectionViewCell {
            cell.initValue(review: restaurantReview)
            cell.layoutSubviews()
        }
        return cell
    }
    
    override func didUpdate(to object: Any) {
        restaurantReview = object as? RestaurantReview
    }
    
    override func didSelectItem(at index: Int) {

    }
}

